package com.ruoyi.devops.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.devops.domain.InspectionTemplate;
import com.ruoyi.devops.mapper.InspectionTemplateMapper;
import com.ruoyi.devops.service.IInspectionTemplateService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

@Service
public class InspectionTemplateService extends ServiceImpl<InspectionTemplateMapper,InspectionTemplate> implements IInspectionTemplateService {

    @Resource
    InspectionTemplateMapper inspectionTemplateMapper;

    @Override
    public AjaxResult queryInspectionTemplate(Map<String,String> map) {

        QueryWrapper wrapper = new QueryWrapper<InspectionTemplate>();

        String describe = map.get("describeInfo");
        String templateType = map.get("templateType");
        String templateName = map.get("templateName");
        String objType = map.get("objType");
        String functionType = map.get("functionType");

        if (StringUtils.isNotEmpty(describe) && !"null".equals(describe)) {
            wrapper.like("describe_info",describe);
        }
        if (StringUtils.isNotEmpty(templateType) && !"null".equals(templateType)) {
            wrapper.like("template_type",templateType);
        }
        if (StringUtils.isNotEmpty(templateName) && !"null".equals(templateName)) {
            wrapper.like("template_name",templateName);
        }
        if (StringUtils.isNotEmpty(objType) && !"null".equals(objType)) {
            wrapper.like("obj_type",objType);
        }
        if (StringUtils.isNotEmpty(functionType) && !"null".equals(functionType)) {
            wrapper.like("function_type",functionType);
        }
        List<InspectionTemplate> list = inspectionTemplateMapper.selectList(wrapper);

        int pp = Integer.parseInt(map.get("page"));

        int ss = Integer.parseInt(map.get("size"));

        wrapper.last("limit "+(pp -1 ) * ss +","+map.get("size"));

        List<InspectionTemplate> list1 = inspectionTemplateMapper.selectList(wrapper);

        return AjaxResult.success(String.valueOf(list.size()),list1);



    }

    public InspectionTemplate queryInspectionTemplateById(InspectionTemplate inspectionTemplate) {
        String id = inspectionTemplate.getId();

        InspectionTemplate re = inspectionTemplateMapper.selectById(id);
        return re;
    }



    public int delInspectionTemplate(InspectionTemplate inspectionTemplate) {
        String id = inspectionTemplate.getId();
        return inspectionTemplateMapper.deleteById(id);
    }

    public int updInspectionTemplate(InspectionTemplate inspectionTemplate) {
        String id = inspectionTemplate.getId();
        return inspectionTemplateMapper.updateById(inspectionTemplate);
    }


}
